var app = getApp();

Page({
  data: {
    page: 1,
    order: [],
    index: 0,
    ac_index: 0,
    order_index: 0,
    acti_index: 0,
    sellers_id: 0
  },
  onLoad (query) {
    app.getUrl(this)
    app.getSystem(this)
    this.setData({
      store_info: wx.getStorageSync("store_info"),
      type: query.type
    });
    this.getRoomList()
  },
  /**
   * @function 下拉刷新
   */
  onPullDownRefresh: function () {
    console.log(this.data.order_index)
    this.setData({
      page: 1,
      order: []
    })
    this.getRoomList(() => {
      wx.stopPullDownRefresh()
    })
  },
  /**
   * 获取房型列表
   * @param {*} cb 请求成功的回调cb，因为之前封装没有promise
   */
  getRoomList (cb) {
    var s = this,
      a = s.data.store_info;
    app.util.request({
      url: "entry/wxapp/RoomList",
      cachetime: "0",
      data: {
        seller_id: a.seller_id
      },
      success: function (t) {
        var a = t.data;
        for (var e in a) e % 2 == 0 ? (a[e].img = "https://llz-img-resources.oss-cn-hangzhou.aliyuncs.com/llz-mina-img/workbench/dididi@2x.png", a[e].class = "back_one") : (a[e].img = "https://llz-img-resources.oss-cn-hangzhou.aliyuncs.com/llz-mina-img/workbench/house_management_one.png",
          a[e].class = "back_two");
        s.setData({
          room: a
        });
        cb && cb()
        console.log(a, "a是扫码")
      }
    });
  },
  /**
   * @function 跳转到房型编辑
   * @param {*} t 
   */
  goEditHouse (t) {
    console.log(']]]]]]')
    wx.navigateTo({
      url: "./editHouse/index?id=" + t.currentTarget.dataset.id
    });
  },
  search: function (t) {
    wx.navigateTo({
      url: "search"
    });
  },
  /**
   * @function  房型上下架
   * @param {*} t 
   */
  changeRoom (e) {
    const { state, id} = e.currentTarget.dataset
    wx.showModal({
      title: "温馨提示",
      content: `确定要${state==1 ? '上架' : '下架'}吗？`,
      success: (t) => {
        t.confirm && app.util.request({
          url: "entry/wxapp/ChangeRoom",
          data: {
            room_id: id,
            state: 1 == state ? 2 : 1
          },
          success: (res) => {
            if (1 == res.data) {
              wx.showToast({
                title: "修改成功"
              })
              this.getRoomList()
            }
          }
        });
      }
    });
  },
  delete_house: function (t) {
    var a = this,
      e = t.currentTarget.dataset.id;
    wx.showModal({
      title: "",
      content: "确定要删除此房型？",
      success: function (t) {
        t.confirm && app.util.request({
          url: "entry/wxapp/DeleteRoom",
          data: {
            room_id: e
          },
          success: function (t) {
            1 == t.data && (wx.showToast({
              title: "删除成功"
            }), setTimeout(function () {
              a.getRoomList();
            }, 1500));
          }
        });
      }
    });
  },
  jd_jdq: function (t) {
    wx.navigateTo({
      url: "jdq?seller_id=" + this.data.store_info.seller_id
    });
  },
  put_forward: function (t) {
    wx.navigateTo({
      url: "put_forward?seller_id=" + this.data.store_info.seller_id
    });
  },
  put_forward_record: function (t) {
    wx.navigateTo({
      url: "record?seller_id=" + this.data.store_info.seller_id
    });
  },
  reply: function (t) {
    wx.navigateTo({
      url: "reply?seller_id=" + this.data.store_info.seller_id
    });
  },
});